package com.symaster.common.swing.element;

import com.symaster.common.geom.entity.Node;
import com.symaster.common.swing.controller.DragController;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

/**
 * @author yinmiao
 * @version 2022-11-21 11:59
 */
public class GeomEditor<T extends Node> extends JComponent {
    private JPanel root_panel;
    private JPanel c_panel;
    private final Canvas2<T> canvas;

    public GeomEditor(int w, int h) {
        this.canvas = new Canvas2<>(w, h, 120);
        this.canvas.setBackground(new Color(100, 100, 100));
        /*DragController dragController = new DragController(this.canvas);
        dragController.addDragListener(DragController.DRAG_TYPE_CENTER, (s, e) -> {
            System.out.println(s);
        });*/
        /*this.canvas.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });*/
        /*this.canvas.addMouseMotionListener(new MouseMotionListener() {
            @Override
            public void mouseDragged(MouseEvent e) {
                if (canvas.centerMouseButtonPressed) {
                    System.out.println(e.getButton());
                }
            }

            @Override
            public void mouseMoved(MouseEvent e) {

            }
        });*/
        initPage();
    }

    public Canvas2<T> getCanvas() {
        return canvas;
    }

    private void initPage() {
        setLayout(new BorderLayout());
        add(root_panel);
        Layered layered = new Layered(canvas);
        layered.setBackground(new Color(150, 150, 150));
        this.c_panel.add(layered);
    }

    {
        // GUI initializer generated by IntelliJ IDEA GUI Designer
        // >>> IMPORTANT!! <<<
        // DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        root_panel = new JPanel();
        root_panel.setLayout(new BorderLayout(0, 0));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new BorderLayout(0, 0));
        panel1.setPreferredSize(new Dimension(0, 35));
        root_panel.add(panel1, BorderLayout.NORTH);
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new BorderLayout(0, 0));
        panel2.setPreferredSize(new Dimension(250, 0));
        root_panel.add(panel2, BorderLayout.EAST);
        c_panel = new JPanel();
        c_panel.setLayout(new BorderLayout(0, 0));
        root_panel.add(c_panel, BorderLayout.CENTER);
    }

    /** @noinspection ALL */
    public JComponent $$$getRootComponent$$$() {
        return root_panel;
    }

}
